import { Button, Gap, SearchForm, Table } from "@/components";
import { useMyTable, useRowSelection } from "@/hooks";
import { getMyUrlParams } from "@/utils";
import { TASK_KEY } from "@/constants";
import { getColumns, getFields } from "./helper";
import { useNavigate } from "react-router-dom";
import { ColumnsType } from "antd/es/table";
import { Space } from "antd";
import { getRecordList } from "./service";

const record = () => {
  const urlParams = getMyUrlParams();
  // console.log(urlParams);
  const isReported = urlParams.flag === "report";
  const { search, refresh, options, ...restAttrs } = useMyTable({
    service: getRecordList,
    initParams: {
      tableName: urlParams.taskKey,
      // name:
      reportState: isReported ? 2 : 3,
    },
  });

  const tableTitle = TASK_KEY.find(item => item.value === urlParams.taskKey)?.label;

  const rowSelection = useRowSelection({});
  const navigate = useNavigate();
  const jumpToTaskList = () => {
    navigate("/management");
  };

  const onReport = () => {
    console.log(1);
  };
  return (
    <>
      {isReported ? (
        <>
          <SearchForm fields={getFields()} query={search} labelWidth={105} />
          <Gap />
        </>
      ) : null}
      <Table
        title={tableTitle+`${isReported ? "" : "未"}上报列表`}
        rowKey={"id"}
        scroll={{ x: "1200px" }}
        rowSelection={
          isReported
            ? {
                ...rowSelection,
                getCheckboxProps: (record) => {
                  return { disabled: !record.startFlag };
                },
              }
            : null
        }
        extra={
          <Space>
            {/* {isReported && (
              <Button
                type="primary"
                ghost
                onClick={() => {
                  onReport();
                }}
              >
                批量重报
              </Button>
            )} */}
            <Button
              type="primary"
              ghost
              onClick={() => {
                jumpToTaskList();
              }}
            >
              返回任务列表
            </Button>
          </Space>
        }
        columns={getColumns(isReported, options, onReport) as ColumnsType<any>}
        {...restAttrs}
      />
    </>
  );
};
export default record;
